/*
 * Copyright 2007, 2008 Tiberiumlabs
 *
 * This file is part of Tiberiumlabs Lailaps.
 *
 * Tiberiumlabs Lailaps is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * Tiberiumlabs Lailaps is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.tiberiumlabs.lailaps.gui.table;

import javax.swing.JTable;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
import javax.swing.table.TableModel;

/**
 *
 * @author <a href="mailto:paranoid.tiberiumlabs@gmail.com">Paranoid</a>
 */
public class Table extends JTable {

    public Table(TableModel tableModel, TableColumnModel tableColumnModel) {
        super(tableModel, tableColumnModel);
    }

    public void repaintRow(int row, int... columns) {

        // checking row visibility:
        int rowViewIndex = convertRowIndexToView(row);
        if (rowViewIndex < 0) {
            return;
        }

        if (columns != null && columns.length > 0) {
            int height = getRowHeight();
            int y = height * rowViewIndex;
            int x = 0;
            int columnCount = columnModel.getColumnCount();
            for (int i = 0; i < columnCount; i++) {
                TableColumn column = columnModel.getColumn(i);
                for (int j = 0; j < columns.length; j++) {
                    if (column.getModelIndex() == columns[j]) {
                        repaint(0, x, y, column.getWidth(), height);
                    }
                    x += column.getWidth();
                }
            }
        }
    }

}
